package com.swxc.smartorder.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.swxc.smartorder.R;
import com.swxc.smartorder.widget.NumberProgressBar;

/**
 * Author   Administrator
 * Date     2018/4/2
 * Desc     eg
 */
public class DialogProgress extends Dialog {
    TextView mDownloadSize;
    NumberProgressBar mPbProgress;
    TextView mTvTitle;
    private Context mContext;

    public DialogProgress(@NonNull Context context) {
        super(context, R.style.AlertDialogStyle);
        this.mContext = context;
        initView();
    }

    public DialogProgress(@NonNull Context context, @StyleRes int themeResId) {
        super(context, R.style.AlertDialogStyle);
        this.mContext = context;
        initView();

    }

    private void initView() {
        setContentView(R.layout.layout_dialog_progress);
        mDownloadSize = findViewById(R.id.downloadSize);
        mPbProgress = findViewById(R.id.pbProgress);
        mTvTitle = findViewById(R.id.tv_title);

    }

    @Override
    public void show() {
        super.show();
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = mContext.getResources().getDisplayMetrics();
        lp.width = (int) (d.widthPixels * 0.9);
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.CENTER;
        dialogWindow.setAttributes(lp);
    }

    public void setMax(int i) {
        mPbProgress.setMax(i);
    }

    public void setProgress(int progress) {
        mPbProgress.setProgress(progress);
    }

    public void setTitle(String title) {
        mTvTitle.setText(title);
    }

    public void setFileSize(String fileSize) {
        mDownloadSize.setText(fileSize);
    }
}
